package com.hyy.api.util;

import org.apache.commons.lang3.StringUtils;

public class SMSUtil {

    /**
     * 根据byte数据获取编码字符串
     *
     * @param charSet
     * @return
     */
    public static String getCharsetByByte(byte charSet) {

        String dcs = "ASCII";
        switch (charSet) {
            case 0:
                dcs = "ASCII";
                break;
            case 4:
                dcs = "LATIN1";
                break;
            case 8:
                dcs = "UCS2";
                break;
            case 12:
                dcs = "RESERVED";
                break;
            case 15:
                dcs = "GBK";
                break;
        }
        return dcs;
    }

    /**
     * 根据编码字符串获取byte数据
     *
     * @param charSet
     * @return
     */
    public static byte getGeneralDataCodingDcs(String charSet) {
        byte dcs = 0x08;
        if (StringUtils.isEmpty(charSet)) {
            return dcs;
        }
        switch (charSet) {
            case "ASCII":
                dcs |= 0x00;
                break;
            case "LATIN1":
                dcs |= 0x04;
                break;
            case "UCS2":
                dcs |= 0x08;
                break;
            case "RESERVED":
                dcs |= 0x0C;
                break;
            case "GBK":
                dcs |= 0x0F;
                break;
        }
        return dcs;
    }


}
